package com.googlecode.spruce.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "service_result")
public class ServiceResult implements Serializable
{
    /** Serial ID */
    private static final long serialVersionUID = -1803755449214496596L;

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name = "result")
    private int result;

    @Column(name = "message")
    private String output;

    @Column(name = "cdate")
    private Date cdate;

    @ManyToOne
    @JoinColumn(name = "host_id")
    private Host host;

    @ManyToOne
    @JoinColumn(name = "service_id")
    private Service service;

    /**
     * @return the id
     */
    public int getId()
    {
        return id;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(final int id)
    {
        this.id = id;
    }

    /**
     * @return the result
     */
    public int getResult()
    {
        return result;
    }

    /**
     * @param result
     *            the result to set
     */
    public void setResult(final int result)
    {
        this.result = result;
    }

    /**
     * @return the output
     */
    public String getOutput()
    {
        return output;
    }

    /**
     * @param output
     *            the output to set
     */
    public void setOutput(final String output)
    {
        this.output = output;
    }

    public Date getCdate()
    {
        return cdate;
    }

    public void setCdate(final Date cdate)
    {
        this.cdate = cdate;
    }

    /**
     * @return the host
     */
    public Host getHost()
    {
        return host;
    }

    /**
     * @param host
     *            the host to set
     */
    public void setHost(final Host host)
    {
        this.host = host;
    }

    /**
     * @return the service
     */
    public Service getService()
    {
        return service;
    }

    /**
     * @param service
     *            the service to set
     */
    public void setService(final Service service)
    {
        this.service = service;
    }

    /**
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((cdate == null) ? 0 : cdate.hashCode());
        result = prime * result + ((host == null) ? 0 : host.hashCode());
        result = prime * result + ((service == null) ? 0 : service.hashCode());
        return result;
    }

    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(final Object obj)
    {
        if (this == obj)
        {
            return true;
        }
        if (obj == null)
        {
            return false;
        }
        if (getClass() != obj.getClass())
        {
            return false;
        }
        ServiceResult other = (ServiceResult) obj;
        if (cdate == null)
        {
            if (other.cdate != null)
            {
                return false;
            }
        }
        else if (!cdate.equals(other.cdate))
        {
            return false;
        }
        if (host == null)
        {
            if (other.host != null)
            {
                return false;
            }
        }
        else if (!host.equals(other.host))
        {
            return false;
        }
        if (service == null)
        {
            if (other.service != null)
            {
                return false;
            }
        }
        else if (!service.equals(other.service))
        {
            return false;
        }
        return true;
    }

}
